<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>物料入库</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">物料名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="requestnumber" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">申请人</label>
                            <div class="layui-input-inline">
                                <input type="text" name="proposer" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <br>
                        <div class="layui-inline">
                            <label class="layui-form-label">日期范围</label>
                            <div class="layui-input-inline">
                                <input type="text"  name="searchDate" class="layui-input" id="test6" placeholder="请点击">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <!--        <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 新增采购申请 </button>
                        &lt;!&ndash;
                                        <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
                        &ndash;&gt;
                    </div>
                </script>-->

        <!--        <script type="text/html" id="toolbarDemo3">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加物料 </button>
                    </div>
                </script>-->

    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="currentTableBar">

        {{#  if(d.productinstatus == 0){ }}
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">入库</a>
        {{#  } else if(d.agrgrtsts == 1){ }}

        {{#  } }}

    </script>

     <!--   <script type="text/html" id="currentTableBar2">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
-->
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //日期范围渲染
        laydate.render({
            elem: '#test6'
            ,range: true
        });

    });
</script>
<script>
    layui.use(['jquery','form', 'table','laydate'], function () {
        //使用jquery
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;


        //表格渲染
        table.render({
            elem: '#currentTableId',//表格的ID
            url: '/pruductin',
            toolbar: '#toolbarDemo',
            //头部工具栏右侧图标
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',//标题
                layEvent: 'LAYTABLE_TIPS',//事件名
                icon: 'layui-icon-tips'//图标类名
            }],
            cols: [[//表头
                /*
                * type:设置列类型
                * field:设定字段名
                * title:设定标题名
                * sort:是否允许排序
                * toolbar:绑定工具条模板。可在每行对应的列中出现一些自定义的操作性按钮
                * */
                {type: "checkbox"},//设置列类型
                {field: 'serialNumber', title: '流水号',
                    templet: '<div>{{d.schedule.serialNumber}}</div>',
                },
                {field: 'planid', title: '计划编号',
                    templet: '<div>{{d.schedule.planid}}</div>',
                },
                {field: 'wsname', title: '生产车间',
                    templet: '<div>{{d.schedule.workShop.wsname}}</div>'},
                {field: 'number', title: '数量',
                    templet: '<div>{{d.schedule.number}}</div>',
                },
                {field: 'prodectrealamount', title: '实际入库数量',
                },
                {field: 'productinstatus', title: '状态', sort: true,
                    templet: function(d) {
                        var t = d.productinstatus;
                        if(t==0){
                            return '待确认入库'
                        }else if(t==1){
                            return '已确认入库'
                        }
                    }},
                {field: 'productintime', title: '入库时间',
                },
                {field: 'affirmpeople', title: '确认人'},
                {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [5, 10, 15, 20, 25, 30],
            limit: 4,
            page: true,//开启分页
            skin: 'line',
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    requestnumber: data.field.requestnumber,
                    proposer: data.field.proposer,
                    searchDate : data.field.searchDate

                }
            }, 'data');

            return false;
        });



        //tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                //layer.open→打开一个弹出层
                var index = layer.open({
                    //标题
                    title: '编辑用户',
                    //基本层类，可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                    type: 2,
                    shade: 0.2,
                    //最大最小化
                    maxmin: true,
                    shadeClose: true,
                    area: ['60%', '60%'],
                    //内容
                    content: '../../page/store/otherinaffirm.html',
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        body.find('#serialNumber').val(data.schedule.serialNumber);
                    },
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            //表格渲染
            table.render({
                elem: '#RequestUnitTableId',
                url: '/purchasegoods?pupId='+data.purchaseplan.pupId,
                toolbar: '#toolbarDemo3',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '物料详情',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    // {type: "checkbox", width: 50},
                    {field: 'pupId', width: 200, title: '采购编号',templet: '<div>{{d.purchaseplan.pupId}}</div>' },
                    {field: 'maename', width: 180, title: '物料名称',templet: '<div>{{d.material.maename}}</div>'},
                    {field: 'model', width: 180, title: '规格型号', templet: '<div>{{d.material.model}}</div>'},
                    {field: 'texture', width: 180, title: '材质',templet: '<div>{{d.material.texture}}</div>'},
                    {field: 'unit', title: '计件单位', minWidth: 150,templet: '<div>{{d.material.unit}}</div>',sort: true},
                    {field: 'quantity', width: 80, title: '数量',templet: '<div>{{d.quantity}}</div>'},
                    {title: '操作', minWidth: 100, toolbar: '#currentTableBar2', align: "center"}

                ]],
                //隐藏编号列
                done: function () {
                    $("[data-field='puiId']").css('display','none');
                },
                limits: [4, 8, 16, 24],
                limit: 4,
                page: true,
                skin: 'line',

            });

            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        });



    });
</script>

</body>
</html>